#!/bin/sh

export args=$1

if test ! -f /usr/lib/libnl-3.so.200; then
   ln -s /usr/lib/libnl-3.so.200.26.0 /usr/lib/libnl-3.so.200
fi

if test ! -f /usr/lib/libnl-genl-3.so.200; then
   ln -s /usr/lib/libnl-genl-3.so.200.26.0 /usr/lib/libnl-genl-3.so.200
fi

function wifi_ap_start()
{
	# 如果plat_soc.ko没有加载，那么就加载
	plat_soc=`lsmod | grep "plat_soc"
	if [ -z "$plat_soc" ]; then
		insmod /ko/wifi/plat_soc.ko
	fi

	# 如果wifi_soc.ko没有加载，那么就加载
	wifi_soc=`lsmod | grep "wifi_soc"
	if [ -z "$wifi_soc" ]; then
		insmod /ko/wifi/wifi_soc.ko
	fi

	sleep 0.5;
	hostapd /etc/Wireless/hostapd.conf &
	ifconfig wlan0 192.168.49.1
	udhcpd -S /etc/Wireless/udhcpd.conf &
}

function wifi_ap_stop()
{
	killall hostapd
	killall udhcpd
	sleep 1;
	rmmod wifi_soc.ko
}

case $args in
	start)
		wifi_ap_start
		;;
	stop)
		wifi_ap_stop
		;;
	-h)
		echo 'Options: start stop '
		;;
	*)
		echo 'Use '-h' to display command line options of sub-processes'
		;;
esac
